﻿@model ExceptionsModel
@{
    var showActions = Current.User.Is(ExceptionsRoles.Admin);
    var displayed = Model.Errors.Sum(e => e.DuplicateCount.GetValueOrDefault(1));
}
@functions
{
    string HeaderLink(string text, ExceptionSorts sort)
    {
        var sortStr = sort.ToString();
        var linkSort = Model.Sort != sort
            ? sortStr
            : (sortStr.Contains("Asc")
                ? sortStr.Replace("Asc", "Desc")
                : sortStr.Replace("Desc", "Asc"));
        var qs = Model.RequestQueryString;
        qs.Set("sort", linkSort);
        <a href="?@(qs.ToString())">@text</a>
        return null;
    }
}
<div class="js-exceptions">
    <h5 class="page-header">
        <span class="js-exception-title">@Model.Title</span>
        <span class="pull-right">
            <a href="#/exceptions/filters" class="hover-pulsate@(Model.SearchParams.HasFilterOptions ? " text-warning" : "")"><i class="fa fa-filter" aria-hidden="true"></i></a>
            @if (Model.ShowClearLink)
            {
                <a class="text-danger hover-pulsate js-clear-all" href="#" data-url="@Url.Action(nameof(ExceptionsController.Delete), Context.Request.Query.ToRouteValues())">@Icon.X Clear all non-protected errors</a>
            }
            @Poll.Now(Module.Stores)
        </span>
    </h5>
    <table class="table table-striped table-responsive table-middle table-super-condensed table-hover table-actions table-exceptions js-table-exceptions" data-total-count="@Model.TotalCount" data-title="@Model.Title" data-displayed="@displayed">
        <thead>
            <tr class="sort-row">
                <th class="@(showActions ? "" : "hidden")"></th>
                <th>@HeaderLink("Time", ExceptionSorts.TimeDesc)</th>
                <th>@if(Model.Log != null) {HeaderLink("Type", ExceptionSorts.TypeAsc);} else {HeaderLink("App", ExceptionSorts.AppAsc);}</th>
                <th>@HeaderLink("Error", ExceptionSorts.MessageAsc)</th>
                <th>@HeaderLink("Url", ExceptionSorts.UrlAsc)</th>
                <th>@HeaderLink("Remote IP", ExceptionSorts.IPAddressAsc)</th>
                <th>@HeaderLink("Host", ExceptionSorts.HostAsc)</th>
                <th>@HeaderLink("Server", ExceptionSorts.MachineNameAsc)</th>
                <th>@HeaderLink("Count", ExceptionSorts.CountDesc)</th>
            </tr>
        </thead>
        <tbody>
            <partial name="Exceptions.Table.Rows" model="Model" />
        </tbody>
    </table>
</div>